package com.yiwei.zxp.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.yiwei.zxp.R;
import com.yiwei.zxp.base.BaseActivity;
import com.yiwei.zxp.fragment.BussinessOrderFragment;
import com.yiwei.zxp.view.HomeViewPager;
import com.yiwei.zxp.view.V19FrameLayout;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

/**
 * Created by xsooy-pc on 17-12-8.
 */

public class BussinessOrderActivity extends BaseActivity {


    @BindView(R.id.btn_back)
    ImageView btnBack;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_right)
    TextView txtRight;
    @BindView(R.id.layout_title)
    V19FrameLayout layoutTitle;
    @BindView(R.id.tablayout)
    TabLayout tablayout;
    @BindView(R.id.pager)
    HomeViewPager pager;
    private Unbinder unbiner;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_buyer_order);
        initBar();
        unbiner = ButterKnife.bind(this);
        init();
    }

    private void init() {
        int poi = getIntent().getIntExtra("poi", 0);
        txtTitle.setText("我的订单");
        String[] titles = new String[]{"全部", "待付款", "待发货", "待收货", "已完成"};
        Fragment[] fragments = new Fragment[5];
        for (int i = 0; i < 5; i++) {
            BussinessOrderFragment fragment = new BussinessOrderFragment();
            Bundle bundle = new Bundle();
            bundle.putInt("id", i);
            fragment.setArguments(bundle);
            fragments[i] = fragment;
        }

        pager.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public CharSequence getPageTitle(int position) {
                return titles[position];
            }

            @Override
            public Fragment getItem(int position) {
                return fragments[position];
            }

            @Override
            public int getCount() {
                return fragments.length;
            }
        });
        tablayout.setupWithViewPager(pager);
        pager.setCurrentItem(poi);
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        unbiner.unbind();
        unbiner = null;
    }

    @OnClick(R.id.btn_back)
    public void onViewClicked() {
        finish();
    }
}
